package com.server.questionbank.snframe.mapper.QuestionBank;

import com.server.questionbank.snframe.domain.User.UansRecord;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 用户答题记录
 */
@Mapper
public interface UansRecordMapper {

    /**
     * 新增答题记录
     * @param record
     * @return
     */
    @Insert("INSERT INTO uans_record(record_id, user_id, exercises_id, publish_id, answer_status, " +
            "submit_time, mark_time, mark_man, full_mark, score, exercise_comment) " +
            "VALUES(#{recordId}, #{userId}, #{exercisesId}, #{publishId}, #{answerStatus}, " +
            "#{submitTime}, #{markTime}, #{markMan}, #{fullMark}, #{score}, #{exerciseComment})")
    @Options(useGeneratedKeys = true, keyProperty = "recordId")
    int insertUansRecord(UansRecord record);

    /**
     * 修改答题记录
     * @param record
     * @return
     */
    @Update("UPDATE uans_record SET " +
            "user_id = #{userId}, " +
            "exercises_id = #{exercisesId}, " +
            "publish_id = #{publishId}, " +
            "answer_status = #{answerStatus}, " +
            "submit_time = #{submitTime}, " +
            "mark_time = #{markTime}, " +
            "mark_man = #{markMan}, " +
            "full_mark = #{fullMark}, " +
            "score = #{score}, " +
            "exercise_comment = #{exerciseComment} " +
            "WHERE record_id = #{recordId}")
    int updateUansRecord(UansRecord record);

    /**
     * 查询答题记录
     * @param recordId
     * @return
     */
    @Select("SELECT * FROM uans_record WHERE record_id = #{recordId}")
    UansRecord selectById(@Param("recordId") Long recordId);

    /**
     * 根据用户查询答题记录列表
     * @param UserId
     * @return
     */
    @Select("SELECT * FROM uans_record WHERE record_id = #{recordId}")
    List<UansRecord> getRecordsByUserId(@Param("UserId") Long UserId);

}
